import { message, Modal, ModalFuncProps } from "antd";
import { ExclamationCircleOutlined } from "@ant-design/icons";
const { confirm } = Modal;
export const handleDeleteAssets = (
    handleCallbackFun: () => Promise<{ code: number; msg: string }>,
    handleDeleteOkCallback: () => void
) => {
    confirm({
        title: "确定要删除吗?",
        icon: <ExclamationCircleOutlined />,
        okText: "删除",
        okType: "danger",
        cancelText: "取消",
        onOk: async () => {
            const values = await handleCallbackFun();
            if (values.code === 20000) {
                message.success("删除成功");
                handleDeleteOkCallback();
            } else {
                message.error(values.msg);
            }
        },
    });
};
// 删除
export const handleDeleteObj = (
    handleCallbackFun: () => Promise<{ code: number; msg: string }>,
    handleDeleteOkCallback: () => void
): ModalFuncProps => {
    return {
        title: "确定要删除吗?",
        icon: <ExclamationCircleOutlined />,
        okText: "删除",
        okType: "danger",
        cancelText: "取消",
        onOk: async () => {
            const values = await handleCallbackFun();
            if (values.code === 20000) {
                message.success("删除成功");
                handleDeleteOkCallback();
            } else {
                message.error(values.msg);
            }
        },
    };
};
// 作废
export const handleCancelFun = (
    handleCallbackFun: () => Promise<{ code: number; msg: string }>,
    handleCancelOkCallback: () => void
): ModalFuncProps => {
    return {
        title: "确定要作废吗?",
        icon: <ExclamationCircleOutlined />,
        okText: "作废",
        okType: "danger",
        cancelText: "取消",
        onOk: async () => {
            const values = await handleCallbackFun();
            if (values.code === 20000) {
                message.success("作废成功");
                handleCancelOkCallback();
            } else {
                message.error(values.msg);
            }
        },
    };
}